<?php

// 热门标签 2017-11-16
class tag_top_auto_cache extends auto_cache {

    private $key = "tag:top";

    public function load($param) {
        $list = $GLOBALS['cache']->get($this->key);

        $key_bf = $this->key . '_bf';
        $list=false;
        if ($list === false) {
            $is_ok = $GLOBALS['cache']->set_lock($this->key);
            if (!$is_ok) {
                $list = $GLOBALS['cache']->get($key_bf, true);
            } else {
                $sql = "select id, title from " . DB_PREFIX . "user_video_tags order by id desc limit 8";

                $list = $GLOBALS['db']->getAll($sql, true, true);
                $list[] = array('id' => 0, 'title' => '热门标签    >');

                $GLOBALS['cache']->set($this->key, $list, 10, true);
                $GLOBALS['cache']->set($key_bf, $list, 86400, true); //备份24小时
            }
        }

        if ($list == false)
            $list = array();

        return $list;
    }

    public function rm($param) {
        $GLOBALS['cache']->rm($this->key);
    }

    public function clear_all() {
        $GLOBALS['cache']->rm($this->key);
    }

}

?>